package main

import "fmt"

// 无法直接更新 struct 的字段值
type data struct {
	name string
}

func main() {
	// m := map[string]data{
	// 	"x": {"Tom"},
	// }
	// m["x"].name = "Jerry" //cannot assign to struct field m["x"].name in map

	m := map[string]*data{
		"x": {"Tom"},
	}

	m["x"].name = "Jerry" // 直接修改 m["x"] 中的字段
	fmt.Println(m["x"])   // &{Jerry}

	// m := map[string]*data{
	// 	"x": {"Tom"},
	// }
	// m["z"].name = "what???"   //panic: runtime error: invalid memory address or nil pointer dereference
	// fmt.Println(m["x"])
}
